package com.googlecode.grtframework.core;

/**
 * 
 * @author ajc
 * 
 */
public abstract class GRTRunningProcess extends Thread implements IProcess {

	private final int sleepTime;
	private boolean running = false;

	/**
	 * 
	 * @param sleepTime
	 *            time(ms) between calls to {@link #step()}
	 */
	public GRTRunningProcess(int sleepTime) {
		this.sleepTime = sleepTime;
	}

	public void startRunning() {
		start();
	}

	public void stopRunning() {
		running = false;
	}

	public boolean isRunning() {
		return running;
	}

	public void run() {
		running = true;
		while (running) {
			step();
			try {
				Thread.sleep(sleepTime);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * 
	 */
	protected abstract void step();

}
